<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>国家公路网综合养护管理系统</title>
<block th:replace="commonBase"></block>
<link
	th:href="@{/common/res/third-party/scrollbar/jquery.mCustomScrollbar.css}"
	rel="stylesheet" type="text/css" />
<script
	th:src="@{/common/res/third-party/scrollbar/jquery.mCustomScrollbar.concat.min.js}"
	type="text/javascript"></script>
<link rel="stylesheet"
	th:href="@{/common/js/miniui/res/font-awesome/css/font-awesome.min.css}" />
<link th:href="@{/common/frame/frame1/res/menu/menu.css}"
	rel="stylesheet" type="text/css" />
<script th:src="@{/common/frame/frame1/res/menu/menu.js}"
	type="text/javascript"></script>
<script th:src="@{/common/frame/frame1/res/menutip.js}"
	type="text/javascript"></script>
<link th:href="@{/common/frame/frame1/res/tabs.css}" rel="stylesheet"
	type="text/css" />
<link th:href="@{/common/frame/frame1/res/frame.css}" rel="stylesheet"
	type="text/css" />
<link th:href="@{/common/frame/frame1/res/index.css}" rel="stylesheet"
	type="text/css" />
<link th:href="@{/common/frame/frame1/res/kz_style.css}"
	rel="stylesheet" type="text/css" />
</head>
<body>
	<div class="navbar">
		<div class="navbar-header">
			<div class="navbar-brand color">国家公路网综合养护管理系统</div>
			<div class="navbar-brand navbar-brand-compact">路</div>
		</div>
		<div class="navbar-right1">
			<ul class="nav navbar-nav" th:each="mods:${user.systems}">
				<li class="icontop"><a href="javascript:void(0);"
					th:onclick="'javascript:loadPage(\''+${mods.id}+'\',\''+${mods.serverId}+'\',\''+${mods.moduleLink}+'\');'"><i
						th:attr="class=${mods.iconCls}"></i><span
						th:text="${mods.moduleName}"></span></a></li>
			</ul>
			<ul class="nav navbar-nav navbar-right-">
				<li class="dropdown">
					<a class="dropdown-toggle userinfo"> 
						<img class="user-img" th:src="@{/dist/img/avatar04.png}" />
				 		<span class="hidden-xs" th:text="${user.name}"></span>
					</a>
				<!-- 	<ul class="dropdown-menu pull-right">
						<li><a href="javascript:void(0);" onclick="infofnc()"><span
								class="fa fa-user"></span>&nbsp;基本资料</a></li>
						<li><a href="javascript:void(0);" onclick="setfnc()"><span
								class="fa fa-cog"></span>&nbsp;个性设置</a></li>
						<li><a href="javascript:void(0);" onclick="logout()"><span
								class="fa fa-sign-out"></span>&nbsp;退出</a></li>
					</ul> -->
				</li>
			</ul>
		</div>
	</div>
	<div class="container">
		<div class="sidebar">
			<div class="sidebar-toggle">
				<i class="fa fa-fw fa-dedent"></i>
			</div>
			<div id="mainMenu"></div>
		</div>

		<div class="main">
			<div id="mainTabs" class="mini-tabs main-tabs" activeIndex="0"
				style="height: 100%;" plain="false" buttons="#tabsButtons"
				arrowPosition="side">
				<div name="index" iconCls="fa-android" title="首页">
					<div class="layui-tab-item layui-show"
						style="height: 100%; overflow-y: hidden;">
						<iframe style="margin-left: -8px;" id="contextframe"
							name="iframe0" width="100%" height="100%" th:src="@{/appli}"
							frameborder="0"></iframe>
					</div>
				</div>
			</div>
			<div id="tabsButtons">
		<!-- 		<a class="tabsBtn"><i class="fa fa-home"></i></a> 
				<a class="tabsBtn"><i class="fa fa-refresh"></i></a> -->
				 <a class="tabsBtn" title="关闭其他选项卡" href="javascript:void(0);" onclick="closeTab()"><i class="fa fa-remove"></i></a>
				  <a class="tabsBtn" title="退出登录" href="javascript:void(0);" onclick="logout()"><i class="fa fa-sign-out"></i></a>
			</div>
		</div>
	</div>
	<script th:inline="javascript" type="text/javascript">
 /*<![CDATA[*/
    function activeTab(item) {
        var tabs = mini.get("mainTabs");
        var tab = tabs.getTab(item.id);
        if (!tab) {
            tab = { name: item.id, title: item.text, url: item.url, iconCls: item.iconCls, showCloseButton: true };
            tab = tabs.addTab(tab);
        }
        tabs.activeTab(tab);
    }
    var cotextRoot = /*[[@{/}]]*/
    var menu = null;
    $(function () {


     	//加载数据字典表添加到localstorage中;
	   	 var storage=window.localStorage;
	   	 if(storage.getItem("dictData")==null ||storage.getItem("dictData")==""){
		   		$.ajax({  
		            type: "get",  
		            dataType: "json",  
		            url: basePath+"dict/list",  
		            data:null,  
		            success: function (data) {  
		            	var dictData=JSON.stringify(data);
		                 storage.setItem("dictData",dictData);
		            } 
		        });  
	   	 }
        
    	 var menu = new Menu("#mainMenu", {
             itemclick: function (item) {
                 if (!item.children) {
                     activeTab(item);
                 }
             }
         });

         $(".sidebar").mCustomScrollbar({ autoHideScrollbar: true });

         new MenuTip(menu);


         
         var sysId = /*[[${sysId}]]*/
                
        if(null != sysId && ''!=sysId){
            $.ajax({
    	    	type: 'POST',
    	    	async: true,
    	        url: basePath+"module/menulist?systemId="+sysId,
    	        success: function (reptext) {
    		        	var childText = getJsonTree(reptext,sysId);
    		        	var treetext = JSON.stringify(childText);
    		        	var reg =new RegExp(/,"children":\[\]/,"g");
    		        	treetext = treetext.replace(reg,"")
    		            var data = mini.decode(treetext);
    		            menu.loadData(data);
    		          
    		    }
    	    }) 
         }else{
             //active first system menu default. 
        	  var sys =  /*[[${user.systems}]]*/

			if(!sys  || '' == sys){
				  			menu.loadData(sys);
							return false;
			}
        	  var id = sys[0].id;
        	  var serverId = sys[0].serverId;
        	  var moduleName = sys[0].moduleName;
        	  var moduleLink = sys[0].moduleLink;
			  if(null != moduleLink && ''!=moduleLink){
				        	  $('body').attr("class","compact");
				              mini.layout();
				             if(null == serverId || '' ==serverId || 'null' == serverId){
				       	 		$("#contextframe").attr("src",cotextRoot+'/'+moduleLink);
				         	}else{
				         		$("#contextframe").attr("src",serverId+'/'+moduleLink);
				             }
			   }else{
				   $.ajax({
		    	    	type: 'POST',
		    	    	async: true,
		    	        url: basePath+"module/menulist?systemId="+id,
		    	        success: function (reptext) {
		    		        	var childText = getJsonTree(reptext,id);
		    		        	var treetext = JSON.stringify(childText);
		    		        	var reg =new RegExp(/,"children":\[\]/,"g");
		    		        	treetext = treetext.replace(reg,"")
		    		            var data = mini.decode(treetext);
		    		            menu.loadData(data);
		    		          
		    		    }
		    	    }) 

					
				}
          }     

         
         
        //toggle
        $("#toggle, .sidebar-toggle").click(function () {
            $('body').toggleClass('compact');
            mini.layout();
        });

        //dropdown
        $(".dropdown-toggle").click(function (event) {
            $(this).parent().addClass("open");
            return false;
        });

        $(document).click(function (event) {
            $(".dropdown").removeClass("open");
        });

    
      
    });


	/**
	*生成tree满足的json数据
	**/
    function getJsonTree(reptext,parentId){
        var itemArr=[];
        var data  = JSON.parse(reptext);
         for(var i=0;i<data.length;i++){ 
            var node=data[i];
             if(node.pid==parentId){ 
                var newNode={id:node.id,iconCls:node.iconCls,text:node.text,url:node.url,children:getJsonTree(reptext,node.id)};
                itemArr.push(newNode);              
             }
        }
        return itemArr;
    }


    function logout(){

    	 mini.confirm("确定退出系统？", "确定？",
    	            function (action) {
    	                if (action == "ok") {
    	                	window.location.href =cotextRoot+"logout";
    	                } else {
    	                }
    	            }
    	        );
        
    }

    function closeTab(){
    	 var tabs = mini.get("mainTabs");
    	 var tab = tabs.getActiveTab();
    	 tabs.removeAll(tab); 
     }
    

    //加载整个页面
    function loadPage(aid,serverId,link){
    	
    	//$(".sidebar").css("display","none");
        if(link && null != link && ""!= link){
        	$('body').attr("class","compact");
             mini.layout();
        	if(null == serverId || '' ==serverId || 'null' == serverId){
      	 		$("#contextframe").attr("src",cotextRoot+'/'+link);
        	}else{
        		$("#contextframe").attr("src",serverId+'/'+link);
            }
        }else{
        	$('body').attr("class","");
             mini.layout();
        	window.location.href = basePath+"index?sysId="+aid
        }
   		
    }
/*]]>*/
</script>
</body>
</html>